package top.babyyan.base.config;

import top.babyyan.base.entity.Result;
import top.babyyan.base.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

/**
 * 功能模块-中文描述
 * @author lenovo
 * @since 2024/9/10 下午7:42
 */
@ControllerAdvice
@RestController
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(BusinessException.class)
    public Result handleGlobalException(BusinessException ex) {
        log.error(ex.getMessage(),ex);
        return Result.fail(ex.getCode(),ex.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public Result handleGlobalException(Exception ex) {
        log.error(ex.getMessage(),ex);
        return Result.fail(500,ex.getMessage());
    }
}
